<?php
class slideViewer {
    function get_gallery($rowName, $id, $path) {
        $connect = new mysqli(DB_HOST,DB_USER,DB_PASS,DB_NAME);
        if($id == null) {
            $result = $connect->query("SELECT SUBSTRING(summary, 1, 200 )AS shortSummary, summary, SUBSTRING(title, 1, 29 ) AS smallTitle, title, id, time, featured, ".$rowName." FROM ".$prefix."posts WHERE draft = '0' AND featured = '1' ORDER BY time DESC LIMIT 0, 7");
            while($row = $result->fetch_object()) {
                $time = date('m-d',strtotime($row->time));
                if(strlen($row->summary) > strlen($row->shortSummary)) {
                    $dots = "...";
                }
                else {
                    $dots = "";
                }
                $this->gallery[] = array(
                    "time" => $time,
                    "id" => $row->id,
                    "smallTitle" => $row->smallTitle,
                    "title" => $row->title,
                    "image" => $row->featured_img,
                    "summary" => $row->shortSummary,
                    "dots" => $dots
                );
            }
            return $this->gallery;
            $result->close();
        }
        else {
            $result = $connect->query("SELECT ".$rowName." FROM ".$prefix."posts WHERE id = '".$id."' ORDER BY id DESC");
            $row = $result->fetch_object();
            $this->gallery = $row->$rowName;
            $urls = explode(', ', $this->gallery);
            foreach($urls as $key => $value) {
                $images[$key] = '<li><img src="'.$path.'/'.$value.'" title="'.$value.'" alt="'.$value.'" /></li>';
            }
            $this->gallery = implode('', $images);
            if(!empty($row->gallery)) {
                return $this->gallery;
            }
            else {
                return false;
            }
            $result->close();
        }
    }
}
?>